# -*- coding: utf-8 -*-
# @Time : 2022-01-20 18:24
# @Author : Z
# @Function : 文件上传和下载
import json

import requests
#
session = requests.session()
url = "http://testingedu.com.cn:8000/index.php/home/Uploadify/imageUp/savepath/head_pic/pictitle/banner/dir/images.html"
files = {
    "file": ("logo.png", open("../../lib/imgs/test.png", "rb"), "image/jpeg")
}
data = {
    "id": "WU_FILE_0",
    "name": "test.png",
    "type": "image/jpeg"
}
response = session.post(url=url, data=data, files=files)
print(response.json())

# url = 'http://httpbin.org/post'
# # 直接通过open函数打开文件并将文件对象存在字典中
# files = {'file': open('../lib/HTTP接口用例.xlsx', 'rb')}
# r = session.post(url, files=files)
# a =r.text
# # print(a)
# print(json.loads(a))


# from Keywords.inter_keys import Inter
#
# inter = Inter()
# inter.post_upload(
#     "http://testingedu.com.cn:8000/index.php/home/Uploadify/imageUp/savepath/head_pic/pictitle/banner/dir/images.html",
#     "test.png", "image/jpeg", 'id=WU_FILE_0&name=logo.png&type=image/jpeg')
#
# inter.assert_equals("state", "SUCCESS")

# inter.post_upload('http://httpbin.org/post', 'HTTP接口用例.xlsx')
# inter.assertequals('url', 'http://httpbin.org/post')

# 文件下载
r = requests.get('https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic%2Fc7%2F13%2Faa%2Fc713aaa432c4e86e79178bc8d72ba487.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1664027637&t=127a1c37fd36bab92340c59f66ef148e')
# print(r.headers)
# 打开一个文件
f = open('../../lib/imgs/meinv.jpg',mode='wb')
f.write(r.content)
f.close()
# print(r.text)

r = requests.get('https://cdn.npmmirror.com/binaries/chromedriver/100.0.4896.20/chromedriver_win32.zip')
# print(r.headers)
# 打开一个文件
f = open('../../lib/meinv.zip',mode='wb')
f.write(r.content)
f.close()
